<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<script>
    require(['jquery'], function($){
        $('[data-role=toggle-editability-all]').change(function(e) {
            var toggler = $(this);
            var field = toggler.parents('.field');
            var someEditable = $('input[type!="checkbox"], select, textarea', field);
            var someEditableCheckboxes = $('input[type="checkbox"]', field).not(toggler);
            if(someEditableCheckboxes.length){
                someEditable.prop('disabled', !toggler.prop('checked') || someEditableCheckboxes.prop('checked'));
                someEditableCheckboxes.prop('disabled', !toggler.prop('checked'));
            } else {
                someEditable.prop('disabled', !toggler.prop('checked'));
            }
        });
        $('[data-role=toggle-editability]').change(function(e) {
            var useConfigSettings = $(this);
            var field = useConfigSettings.parents('.field');
            var someEditable = $('input[type!="checkbox"], select, textarea', field);
            someEditable.prop('disabled', useConfigSettings.prop('checked'));
        });
    });
</script>

<div class="fieldset-wrapper form-inline advanced-inventory-edit">
    <div class="fieldset-wrapper-title">
        <strong class="title">
            <span><?php /* @escapeNotVerified */ echo __('Advanced Inventory') ?></span>
        </strong>
    </div>
    <div class="fieldset-wrapper-content">
        <fieldset class="fieldset" id="table_cataloginventory">
        <div class="field">
            <label class="label" for="inventory_manage_stock">
                <span><?php /* @escapeNotVerified */ echo __('Manage Stock') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <select id="inventory_manage_stock" name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[manage_stock]"
                                class="select" disabled="disabled">
                            <option value="1"><?php /* @escapeNotVerified */ echo __('Yes') ?></option>
                            <option
                                value="0"<?php if ($block->getFieldValue('manage_stock') == 0): ?> selected="selected"<?php endif; ?>><?php /* @escapeNotVerified */ echo __('No') ?></option>
                        </select>
                    </div>
                    <div class="field choice">
                        <input name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[use_config_manage_stock]" type="checkbox"
                               id="inventory_use_config_manage_stock" data-role="toggle-editability" value="1"
                               checked="checked" disabled="disabled"/>
                        <label for="inventory_use_config_manage_stock"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Use Config Settings') ?></span></label>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_manage_stock_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_manage_stock_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field required">
            <label class="label" for="inventory_qty">
                <span><?php /* @escapeNotVerified */ echo __('Qty') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <input type="text" class="input-text required-entry validate-number" id="inventory_qty"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[qty]"
                               value="<?php /* @escapeNotVerified */ echo $block->getDefaultConfigValue('qty') * 1 ?>" disabled="disabled"/>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_qty_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_qty_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field with-addon">
            <label class="label" for="inventory_min_qty">
                <span><?php /* @escapeNotVerified */ echo __('Out-of-Stock Threshold') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <input type="text" class="input-text validate-number" id="inventory_min_qty"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[min_qty]"
                               value="<?php /* @escapeNotVerified */ echo $block->getDefaultConfigValue('min_qty') * 1 ?>" disabled="disabled"/>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_use_config_min_qty"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[use_config_min_qty]" value="1"
                               data-role="toggle-editability" checked="checked" disabled="disabled"/>
                        <label for="inventory_use_config_min_qty" class="label">
                            <span><?php /* @escapeNotVerified */ echo __('Use Config Settings') ?></span>
                        </label>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_min_qty_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_min_qty_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field">
            <label class="label" for="inventory_min_sale_qty">
                <span><?php /* @escapeNotVerified */ echo __('Minimum Qty Allowed in Shopping Cart') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <input type="text" class="input-text validate-number" id="inventory_min_sale_qty"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[min_sale_qty]"
                               value="<?php /* @escapeNotVerified */ echo $block->getDefaultConfigValue('min_sale_qty') * 1 ?>"
                               disabled="disabled"/>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_use_config_min_sale_qty"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[use_config_min_sale_qty]" value="1" data-role="toggle-editability" checked="checked" disabled="disabled"/>
                        <label for="inventory_use_config_min_sale_qty"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Use Config Settings') ?></span></label>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_min_sale_qty_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_min_sale_qty_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field">
            <label class="label" for="inventory_max_sale_qty">
                <span><?php /* @escapeNotVerified */ echo __('Maximum Qty Allowed in Shopping Cart') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <input type="text" class="input-text validate-number" id="inventory_max_sale_qty"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[max_sale_qty]"
                               value="<?php /* @escapeNotVerified */ echo $block->getDefaultConfigValue('max_sale_qty') * 1 ?>"
                               disabled="disabled"/>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_use_config_max_sale_qty"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[use_config_max_sale_qty]" value="1" data-role="toggle-editability" checked="checked" disabled="disabled"/>
                        <label for="inventory_use_config_max_sale_qty"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Use Config Settings') ?></span></label>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_max_sale_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_max_sale_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field">
            <label class="label" for="inventory_is_qty_decimal">
                <span><?php /* @escapeNotVerified */ echo __('Qty Uses Decimals') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <select id="inventory_is_qty_decimal"
                                name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[is_qty_decimal]" class="select"
                                disabled="disabled">
                            <option value="0"><?php /* @escapeNotVerified */ echo __('No') ?></option>
                            <option
                                value="1"<?php if ($block->getDefaultConfigValue('is_qty_decimal') == 1): ?> selected="selected"<?php endif; ?>><?php /* @escapeNotVerified */ echo __('Yes') ?></option>
                        </select>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_is_qty_decimal_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_is_qty_decimal_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field">
            <label class="label" for="inventory_backorders">
                <span><?php /* @escapeNotVerified */ echo __('Backorders') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <select id="inventory_backorders" name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[backorders]"
                                class="select" disabled="disabled">
                            <?php foreach ($block->getBackordersOption() as $option): ?>
                                <?php $_selected = ($option['value'] == $block->getDefaultConfigValue('backorders')) ? ' selected="selected"' : '' ?>
                                <option
                                    value="<?php /* @escapeNotVerified */ echo $option['value'] ?>"<?php /* @escapeNotVerified */ echo $_selected ?>><?php /* @escapeNotVerified */ echo $option['label'] ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_use_config_backorders"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[use_config_backorders]" value="1" data-role="toggle-editability" checked="checked" disabled="disabled"/>
                        <label for="inventory_use_config_backorders"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Use Config Settings') ?></span></label>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_backorders_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_backorders_checkbox" class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>

            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field">
            <label class="label" for="inventory_notify_stock_qty">
                <span><?php /* @escapeNotVerified */ echo __('Notify for Quantity Below') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <input type="text" class="input-text validate-number" id="inventory_notify_stock_qty"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[notify_stock_qty]"
                               value="<?php /* @escapeNotVerified */ echo $block->getDefaultConfigValue('notify_stock_qty') * 1 ?>"
                               disabled="disabled"/>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_use_config_notify_stock_qty"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[use_config_notify_stock_qty]" value="1" data-role="toggle-editability" checked="checked" disabled="disabled"/>
                        <label for="inventory_use_config_notify_stock_qty"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Use Config Settings') ?></span></label>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_notify_stock_qty_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_notify_stock_qty_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field">
            <label class="label" for="inventory_enable_qty_increments">
                <span><?php /* @escapeNotVerified */ echo __('Enable Qty Increments') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <select id="inventory_enable_qty_increments"
                                name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[enable_qty_increments]" class="select"
                                disabled="disabled">
                            <option value="1"><?php /* @escapeNotVerified */ echo __('Yes') ?></option>
                            <option
                                value="0"<?php if ($block->getDefaultConfigValue('enable_qty_increments') == 0): ?> selected="selected"<?php endif; ?>><?php /* @escapeNotVerified */ echo __('No') ?></option>
                        </select>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_use_config_enable_qty_increments"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[use_config_enable_qty_increments]" value="1" data-role="toggle-editability" checked="checked" disabled="disabled"/>
                        <label for="inventory_use_config_enable_qty_increments"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Use Config Settings') ?></span></label>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_enable_qty_increments_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_enable_qty_increments_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field">
            <label class="label" for="inventory_qty_increments">
                <span><?php /* @escapeNotVerified */ echo __('Qty Increments') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <input type="text" class="input-text validate-number" id="inventory_qty_increments"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[qty_increments]"
                               value="<?php /* @escapeNotVerified */ echo $block->getDefaultConfigValue('qty_increments') * 1 ?>"
                               disabled="disabled"/>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_use_config_qty_increments"
                               name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[use_config_qty_increments]" value="1" data-role="toggle-editability" checked="checked" disabled="disabled"/>
                        <label for="inventory_use_config_qty_increments"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Use Config Settings') ?></span></label>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_qty_increments_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_qty_increments_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>

        <div class="field">
            <label class="label" for="inventory_stock_availability">
                <span><?php /* @escapeNotVerified */ echo __('Stock Availability') ?></span>
            </label>

            <div class="control">
                <div class="fields-group-2">
                    <div class="field">
                        <select id="inventory_stock_availability"
                                name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[is_in_stock]" class="select"
                                disabled="disabled">
                            <option value="1"><?php /* @escapeNotVerified */ echo __('In Stock') ?></option>
                            <option
                                value="0"<?php if ($block->getDefaultConfigValue('is_in_stock') == 0): ?> selected<?php endif; ?>><?php /* @escapeNotVerified */ echo __('Out of Stock') ?></option>
                        </select>
                    </div>
                    <div class="field choice">
                        <input type="checkbox" id="inventory_stock_availability_checkbox" data-role="toggle-editability-all"/>
                        <label for="inventory_stock_availability_checkbox"
                               class="label"><span><?php /* @escapeNotVerified */ echo __('Change') ?></span></label>
                    </div>
                </div>
            </div>
            <div class="field-service" value-scope="<?php /* @escapeNotVerified */ echo __('[GLOBAL]') ?>"></div>
        </div>
        </fieldset>
    </div>
</div>
